package punto_de_venta;


import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class Conexion {
    public static Connection conexion;
	public  Statement statement;
	ResultSet resultset;

 static String bd = "petit";
 static String login = "root";
 static String password = "";
 static String url = "jdbc:mysql://localhost/"+bd;

    public void abrirConexion() {


	     try {
	    	 Class.forName("com.mysql.jdbc.Driver").newInstance();

	         // establish connection to database
//	    	 establish connection to database
//             JOptionPane.showMessageDialog( null, "conexion realizada");
conexion = DriverManager.getConnection(url,login,password);
	     } // fin del try

	     //	   detect problems interacting with the database
	     catch ( Exception sqlException ) {
	         JOptionPane.showMessageDialog( null, "error");
	     }
    }

	public void cerrarConexion() {
		try {
           statement.close(); //  .close();
           conexion.close();
           JOptionPane.showMessageDialog(null,"se ha cerrado la conexion");
        }
        // handle exceptions closing statement and connection
        catch ( SQLException sqlException ) {
           JOptionPane.showMessageDialog(null, "error");
           System.exit( 1 );
        }
	}// Fin del metodo para cerrar conexion

         public void InsertarUsuario(String nombre, String direccion, String telefono, String email, String contraseña){
        Connection c;
            try {
                c = DriverManager.getConnection("jdbc:mysql://localhost/petit", "root", "");

                  Statement sql=c.createStatement();
                  sql.execute("insert into usuarios values(0,'"+nombre+"','"+direccion+"','"+telefono+"','"+email+"','"+telefono+"','"+contraseña+"')");

            } catch (SQLException ex) {
                Logger.getLogger(Registro.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(null, "no se pudo realizar conexion");
            }



}
}

